import type {
  PageConfig,
  FormConfig,
  ActionConfig,
  TableActionConfig,
  PaginationConfig,
  DataRecord,
  SearchFieldConfig,
  TableColumn,
} from './config.type'

/**
 * 完整的页面配置
 */
const config = {
  // 页面基本信息
  page: {
    title: '品牌管理',
    description: '管理系统中的品牌信息',
    permission: 'product:trademark',
    targetNameField: 'tmName',
  } as PageConfig,

  // API接口配置
  api: {
    BASE_URL: '/admin/product/baseTrademark',
    CREATE_URL: '/admin/product/baseTrademark/save',
    UPDATE_URL: '/admin/product/baseTrademark/update',
    DELETE_URL: '/admin/product/baseTrademark/remove',
    BATCH_DELETE_URL: '/admin/product/baseTrademark/batchRemove',
    UPLOAD_URL: '/admin/product/fileUpload',
  },

  // 搜索配置
  search: {
    fields: [
      {
        prop: 'brandName',
        label: '品牌名称',
        type: 'input',
        placeholder: '按品牌名称搜索',
        clearable: true,
      },
      {
        prop: 'status',
        label: '状态',
        type: 'select',
        placeholder: '全部状态',
        clearable: true,
        options: [
          { label: '全部', value: '' },
          { label: '启用', value: 'active' },
          { label: '禁用', value: 'inactive' },
        ],
      },
    ] as SearchFieldConfig[],
    showReset: true,
    searchButtonText: '搜索',
    resetButtonText: '重置',
  },

  // 表格列配置
  tableColumns: [
    {
      type: 'selection',
      label: '选择',
      width: 55,
      align: 'center',
    },
    {
      type: 'index',
      label: 'ID',
      width: 80,
      align: 'center',
    },
    {
      prop: 'tmName',
      label: '品牌名称',
      minWidth: 100,
      align: 'center',
    },
    {
      prop: 'logoUrl',
      label: '品牌Logo',
      type: 'image',
      width: 120,
      align: 'center',
      imageConfig: {
        width: 40,
        height: 40,
        round: true,
        preview: true,
        showPlaceholderText: true,
      },
    },
    {
      prop: 'createdAt',
      label: '创建时间',
      type: 'date',
      width: 180,
      align: 'center',
      dateConfig: {
        format: 'YYYY-MM-DD',
      },
    },
  ] as TableColumn<DataRecord>[],

  // 表格操作列按钮配置
  tableActions: [
    {
      text: '编辑',
      label: '编辑',
      type: 'primary' as const,
      size: 'small' as const,
      plain: true,
      permission: 'btn.Trademark.update',
      action: 'edit' as const,
    },
    {
      text: '删除',
      label: '删除',
      type: 'danger' as const,
      size: 'small' as const,
      plain: true,
      permission: 'btn.Trademark.remove',
      action: 'delete' as const,
    },
  ] as TableActionConfig[],

  // 表单配置
  form: {
    fields: [
      {
        prop: 'tmName',
        label: '品牌名称',
        type: 'input',
        placeholder: '请输入品牌名称',
        required: true,
        maxlength: 50,
        showWordLimit: true,
      },
      {
        prop: 'logoUrl',
        label: '品牌Logo',
        type: 'upload',
        placeholder: '请上传品牌Logo',
        required: true,
        uploadConfig: {
          action: '/admin/product/fileUpload',
          name: 'file',
          data: { type: 'brand-logo' },
          accept: 'image/png,image/jpeg,image/gif,image/webp',
          maxSize: 5,
          tips: [
            '支持 PNG、JPEG、GIF、WebP 格式',
            '文件大小不超过 5MB',
            '建议尺寸：200x200 像素',
            '支持透明背景的 PNG 格式',
          ],
        },
      },
    ],
    rules: {
      tmName: [
        { required: true, message: '请输入品牌名称', trigger: 'blur' },
        { min: 2, max: 50, message: '品牌名称长度在 2 到 50 个字符', trigger: 'blur' },
      ],
      logoUrl: [{ required: true, message: '请上传品牌Logo', trigger: 'change' }],
    },
    labelWidth: '100px',
    dialogWidth: '600px',
    addTitle: '新增品牌',
    editTitle: '编辑品牌',
  } as FormConfig,

  // 操作按钮配置
  actions: {
    add: {
      text: '新增品牌',
      icon: 'Plus',
      permission: 'btn.Trademark.add',
    },
    batchDelete: {
      text: '批量删除',
      icon: 'Delete',
      permission: 'btn.Trademark.remove',
    },
  } as ActionConfig,

  // 分页配置
  pagination: {
    pageSizes: [5, 10, 20, 50, 100],
    defaultPageSize: 10,
  } as PaginationConfig,

  // 消息配置
  messages: {
    loadSuccess: '品牌列表获取成功',
    loadError: '品牌列表获取失败',
    addSuccess: '品牌添加成功！',
    addError: '品牌添加失败',
    editSuccess: '品牌修改成功！',
    editError: '品牌修改失败',
    deleteSuccess: '删除成功',
    deleteError: '删除失败',
    batchDeleteSuccess: '批量删除成功',
    batchDeleteError: '批量删除失败',
    uploadSuccess: 'Logo上传成功',
    uploadError: 'Logo图片上传失败',
    selectDeleteItems: '请选择要删除的数据',
    deleteConfirm: '确定要删除这个品牌吗？删除后无法恢复！',
    batchDeleteConfirm: '确定要删除选中的 {count} 个品牌吗？删除后无法恢复！',
  },
}

export default config
